*******************************************************************************
*Table A.2: Comparison of dealer samples
*This table compares the PDS dealers originally sampled at baseline (\original sample") with those added at the first endline as a result of ration card re-assignment across ration shops (\additional sample")
*******************************************************************************



use "${SurveyDataDir}/JHePOS_EL1_Dealer_data.dta",clear

tostring fps_uid, replace
tostring district_code, replace format("%02.0f")
tostring block_code, replace format("%03.0f")
tostring fps_code, replace format("%02.0f")


*merge to get strata
merge m:1 block_code using "${AdminDataDir}/blockLevel_strata.dta", keepusing(strata)
drop _merge



*Label vars for displaying in output table
label var treatment "Treatment"
label var a2_age "Age"
label var a3_education "Years of education"
label var a4_fps_in_past "Has an FPS dealer in family"
label var a5_running_fps "Years as FPS dealer"
label var c6_income_activities "Has other income sources"
label var a6_home_out "Runs FPS out of own home"
label var a7_open_days "Days open per month"
label var a7_open_hours "Hours open per day"
label var a8_govt_days "Days mandated to be open per month"
label var a8_govt_hours "Hours mandated to be open per day"
label var a16_no_hrs_pds "Hours selling PDS commodities per day"
label var a14_rc_count "Number of total ration cards"
label var a14_ph_no "Number of PH ration cards"
label var a14_aay_no "Number of AAY ration cards"
label var a15_no_of_villages "Number of villages"




#delimit ;
loc charVars "treatment a2_age a3_education a4_fps_in_past a5_running_fps c6_income_activities a6_home_out a7_open_days a7_open_hours a8_govt_days a16_no_hrs_pds a8_govt_hours a14_rc_count a14_ph_no a14_aay_no a15_no_of_villages";		
#delimit cr 


preserve
replace fps_new_yesno = 1-fps_new_yesno

*Run balance program
eststo dealer_c: corr_table `charVars', indepvar(fps_new_yesno) condlist(cluster(block_code))
estadd scalar obs=e(N)


restore

#delimit ;								
										
esttab dealer_c using "${OutputDir}/TableA_2.tex", 
	label cells("Mean1(fmt(%12.2gc) label(\specialCellCenter{Original\\sample})) Mean0(fmt(%12.2gc) label(\specialCellCenter{Additional\\sample})) b(star fmt(%12.2gc) label(\specialCellCenter{Regression-\\adjusted \\difference})) p(fmt(%12.2fc) label(\(p\)-value))" )
	booktabs replace  noobs nonumber nolz star(* .10 ** .05 *** .01)  width(\hsize)
	mlabels("")
	substitute("                    &            &            &                     &            \\" "" 
			   "\sym{*}" "*" "\sym{**}" "**" "\sym{**}" "**") 
			   			   ; 
#delimit cr
eststo clear





